package com.caption;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@SpringBootApplication
@MapperScan("com.caption.mapper")
public class StartApplication {

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class,args);
    }

    /////////通用线程池//////////
    @Value("${task.core.size:50}")
    private int commonCorePoolSize;

    @Value("${task.max.size:50}")
    private int commonMaxPoolSize;

    @Value("${task.keepalive.seconds:500}")
    private int commonKeepAliveSeconds;

    @Value("${task.keepalive.seconds:2000}")
    private int commonQueueCapacity;


    /**
     * 通用线程池
     * @return
     */
    @Bean
    public ThreadPoolTaskExecutor commonExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(commonCorePoolSize); //线程池活跃线程数
        executor.setMaxPoolSize(commonMaxPoolSize); // 线程池最大活跃线程数
        executor.setKeepAliveSeconds(commonKeepAliveSeconds);
        executor.setQueueCapacity(commonQueueCapacity); // 队列的最大容量
        return executor;
    }
}
